﻿Imports ACFramework
Imports ACReporteador
Imports C1.C1Preview
Imports C1.Win.C1FlexGrid

Public Class PReporteador

#Region " Variables "
   Private m_lista As List(Of ACLista)
   Private m_listaTmp As List(Of ACLista)
   Private bs_lista As BindingSource
   Private bs_listaFiltrada As BindingSource
   Private m_tipo As TipoLista

   Public Enum TipoLista
      Filtrador
      Ordenador
   End Enum

#End Region

#Region " Propiedades "

#End Region

#Region " Constructores "
   Public Sub New()

      ' This call is required by the Windows Form Designer.
      InitializeComponent()
      ' Add any initialization after the InitializeComponent() call.
      NsTextBoxNumerico1.Text = 100

      TextBox1.Text = "NSCodigo=10 AND NSDescripcion=D%"
      AddHandler Button1.Click, AddressOf Imprimir_Click
      Label2.Text = "Filtrado Por:"
      Me.Text = "FILTRADOR"
      Button1.Text = "Filtrar Lista"
      _flex.Rows.Fixed = 2
      _flex.Rows.Count = 2
   End Sub
#End Region

#Region " Metodos "

#End Region

#Region " Metodos de Controles"
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      Try
         m_lista = New List(Of ACLista)
         Dim i As Integer = CType(NsTextBoxNumerico1.Text, Integer)
         For index As Integer = 1 To i
            m_lista.Add(New ACLista(IIf(CheckBox1.Checked, (Int(Rnd() * i)).ToString(), index.ToString()), "Descripcion: " & index.ToString()))
         Next
         bs_lista = New BindingSource()
         bs_lista.DataSource = m_lista
         _flex.DataSource = bs_lista
         BindingNavigator1.BindingSource = bs_lista
         _flex.Cols(0).Width = 20
         _flex.Rows(1)(1) = _flex.Rows(0)(1)
         _flex.Rows(1)(2) = _flex.Rows(0)(2)

         _flex.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.Custom
         _flex.Cols(2).AllowMerging = True
         _flex.Cols(1).AllowMerging = True

         Dim rg As CellRange = _flex.GetCellRange(0, 1, 0, 2)
         rg.Data = "Titulo"
         _flex.MergedRanges.Add(rg)
         'rg = _flex.GetCellRange(0, 2, 1, 2)
         'rg.Data = "Descripcion"
         '_flex.MergedRanges.Add(rg)


      Catch ex As Exception
         Throw ex
      End Try
   End Sub

   Private Sub Filtrador_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
      Try
         Dim filter As New ACFiltrador(Of ACLista)
         filter.ACFiltro = TextBox1.Text

         bs_listaFiltrada = New BindingSource()
         bs_listaFiltrada.DataSource = filter.ACFiltrar(m_lista)
         C1FlexGrid2.DataSource = bs_listaFiltrada
         BindingNavigator2.BindingSource = bs_listaFiltrada
         C1FlexGrid2.Cols(0).Width = 20
      Catch ex As Exception
         Throw ex
      End Try
   End Sub

   Private Sub Ordenador_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
      Try
         Dim Order As New ACOrdenador(Of ACLista)
         Order.ACOrdenamiento = TextBox1.Text

         bs_listaFiltrada = New BindingSource()
         m_listaTmp = New List(Of ACLista)(m_lista)
         m_listaTmp.Sort(AddressOf Order.ACCompare)
         bs_listaFiltrada.DataSource = m_listaTmp
         C1FlexGrid2.DataSource = bs_listaFiltrada
         BindingNavigator2.BindingSource = bs_listaFiltrada
         C1FlexGrid2.Cols(0).Width = 20
      Catch ex As Exception
         Throw ex
      End Try
   End Sub

   Private Sub Imprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
      Try
         Dim x As New ACPreview(_flex, New ACCabecera(New ACTexto("Cliente"), "Sucursal", "Ruc", New ACTexto() {New ACTexto("aaaaaaaaaaaaaaa"), New ACTexto("BBBBBBBBBBBBBBB"), New ACTexto("ccccccccccccccccc")}, Me.Font))
         x.setCabecera(New ACTexto() {New ACTexto("Titulo 1"), New ACTexto("Titulo 2")})
         x.ACCabecera.setImageTitulo(ACTest.My.Resources.Logo_Titulo_reducido_600x70)

         '#Region "Estilos de columnas"
         'x.setAlinearParaColumnas(New AlignHorzEnum() {AlignHorzEnum.Right, AlignHorzEnum.Right} _
         '                       , New Unit() {New Unit(2, UnitTypeEnum.Cm), New Unit(1, UnitTypeEnum.Cm)} _
         '                       , _flex.Cols.Count - 1)
         'x.setFormatosColumnas(New String() {"N", "N"})
         '#End Region

         '#Region "Texto"

         x.ACTextoLista = New ACTextoLista()
         x.ACTextoLista.Add(New ACTexto("Fletes", New Font(Me.Font, FontStyle.Bold)))
         x.ACTextoLista.Add(New ACTexto("Otro", New Font(Me.Font, FontStyle.Italic)))
         x.ACTextoLista.Add(New ACTexto("Otritos", New Font(Me.Font.FontFamily, 8, FontStyle.Regular)))
         x.ACTextoLista.Add(New ACTexto("Otritos", New Font(Me.Font, FontStyle.Bold)))


         Dim r1 As New ACColumnaAlineacionLista()
         Dim s0 As Unit() = {New C1.C1Preview.Unit(0, UnitTypeEnum.Mm), _
                              New C1.C1Preview.Unit(20, UnitTypeEnum.Mm), _
                              New C1.C1Preview.Unit(150, UnitTypeEnum.Mm)}
         Dim t0 As New ACColumnaAlineacion()
         t0.Ancho = s0

         r1.Add(t0)

         x.ACColumnasLista = New ACColumnaAlineacionLista()
         x.ACColumnasLista = r1

         x.setMargen(5.0, 20.0, 20.0, 20.0, UnitTypeEnum.Mm)
         '#End Region

         '#Region "Estilo Visual"
         x.setEstilo(ACEEstilo.elegant, False)
         Dim line As New LineDef("2pt", Color.Black)
         x.setEstiloLinea(line)
         x.ACEstiloReporte.FuenteTamano = 7
         '#End Region

         '#Region "Padding"
         'string[] padd = { "5mm", "5mm", "5mm", "5mm" };
         'x.setPadding(padd);
         'Dim u As Unit() = {New Unit(15.0, UnitTypeEnum.Mm), New Unit(5.0, UnitTypeEnum.Mm), New Unit(5.0, UnitTypeEnum.Mm), New Unit(5.0, UnitTypeEnum.Mm)}
         'x.setPadding(u)
         ''x.setPadding(new Unit(5.0, UnitTypeEnum.Mm), new Unit(5.0, UnitTypeEnum.Mm), new Unit(5.0, UnitTypeEnum.Mm), new Unit(5.0, UnitTypeEnum.Mm));
         ''x.setPadding("5mm", "5mm", "5mm", "5mm");

         ''x.setPaddingAll("5mm", "5mm");
         ''x.setPaddingAll(new Unit(5.0, UnitTypeEnum.Mm), new Unit(5.0, UnitTypeEnum.Mm));
         ''x.setPaddingCell("5mm", "5mm", "5mm", "5mm");
         'x.setPaddingCeldas(New Unit(5.0, UnitTypeEnum.Mm), New Unit(5.0, UnitTypeEnum.Mm), New Unit(5.0, UnitTypeEnum.Mm), New Unit(5.0, UnitTypeEnum.Mm))
         '#End Region

         '#Region "Fuente"
         Dim f As New Font("Courier New", 8, FontStyle.Regular)
         x.setFuente(f)
         Dim j As New Font(Font.FontFamily, 20, FontStyle.Regular)
         x.ACCabecera.Titulo.Fuente = j

         '#End Region

         'Dim _merged As New ACCeldaCombinadaLista()
         '_merged.Add(New ACCeldaCombinada(1, 1, 3, 3))
         '_merged.Add(New ACCeldaCombinada(4, 4, 5, 5))
         'x.setListaCombinada(_merged)

         x.ACEjecutar()
         x.WindowState = FormWindowState.Maximized
         'x.Ejecutar(_flex, NSEStyle.modern)
         x.ShowDialog()
      Catch ex As Exception
         Throw ex
      End Try
   End Sub

#End Region


End Class